import {request} from "../request";
import {utils} from "../../common/utils";

//1.获取所有菜单信息
export function getMenus({menuName,enabled}){
    return request({
        url: '/sys/menu/query',
        method: 'get',
        params: {
            menuName,
            enabled
        }
    })
}

//2.获取权限菜单选项
export function getMenuOptions() {
    return request({
        url: '/sys/menu/options',
        method: 'get'
    })
}

//3.添加菜单
export function addMenu(menu) {
    return request({
        url: '/sys/menu/add',
        method: 'post',
        data: menu
    })
}

//4.修改菜单
export function updateMenu({
                               id, menuName, sort, path, parentId, type, url,
                               keepAlive, enabled, component, iconId, requireAuth
                           }) {
    return request({
        url: '/sys/menu/update',
        method: 'put',
        data: {
            id,
            menuName,
            sort,
            path,
            parentId,
            type,
            url,
            keepAlive,
            enabled,
            component,
            iconId,
            requireAuth
        }
    })
}

//5.删除菜单
export function deleteMenu(ids) {
    let strUrl = utils.joinArrayReqParam(ids,'ids');
    return request({
        url: '/sys/menu/delete' + strUrl,
        method: 'delete'
    })
}

//6.请求由后端管理的所有菜单资源
export function initMenus(){
    return request({
        url: '/menu-list',
        method: 'get'
    })
}

//7、请求用户的权限菜单资源
export function initUserMenus(){
    return request({
        url: '/user-menu',
        method: 'get'
    })
}

//8、导出菜单
export function exportMenu(){
    return request({
        url: '/sys/menu/export',
        method: 'get',
        responseType: 'arraybuffer'
    })
}

//9、查看是否存在相同路径名称的菜单
export function hasSameMenuPath({id,path}){
    return request({
        url: '/sys/menu/has-same-path',
        method: 'get',
        params:{
            id,
            path
        }
    })
}

//10、查看同一目录下是否存在相同名称的菜单
export function hasSameNameSiblingMenu({id,menuName,parentId}){
    return request({
        url: '/sys/menu/has-same-name-sibling',
        method: 'get',
        params: {
            id,
            menuName,
            parentId
        }
    })
}